//
//  GAOStatuses.swift
//  Weibo28
//
//  Created by 高辰 on 16/5/14.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
//微博数据模型
class GAOStatuses: NSObject {
    //微博创建时间
    var created_at: String?
    //微博ID
    var id: Int64 = 0
    //微博信息内容
    var text: String?
    //微博来源
    var source: String?
    //微博作者的用户信息字段
    var user: GAOUserModel?
    //被转发的原微博信息字段，当该微博为转发微博时返回
    var retweeted_status: GAOStatuses?
    ///转发数
    var reposts_count: Int = 0
    ///评论数
    var comments_count: Int = 0
    ///表态数
    var attitudes_count: Int = 0
    //配图数据(缩略图)
    var pic_urls: [GAOPictureModel]?
    
    //kvc构造函数
    init(dict: [String: AnyObject]) {
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            guard let dict = value as? [String: AnyObject] else {
                return
            }
            user = GAOUserModel(dict: dict)
        }else if key == "retweeted_status" {
            guard let dict = value as? [String: AnyObject] else {
                return
            }
            retweeted_status = GAOStatuses(dict: dict)
            
        }else if key == "pic_urls" {
            //用字典数组接收
            guard let dictArray = value as? [[String: AnyObject]] else {
                return
            }
            //创建空的数组
            var pic_urlArray = [GAOPictureModel]()
            for dict in dictArray {
                let pictureModel = GAOPictureModel(dict: dict)
                pic_urlArray.append(pictureModel)
            }
            pic_urls = pic_urlArray
            
        }else {
            super.setValue(value, forKey: key)
        }
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
}
